#include <QApplication>
#include <QFile>
#include <QtSingleApplication/QtSingleApplication>

#include "mainwindow.h"
QtSingleApplication* a;

int main(int argc, char *argv[])
{
    //QApplication a(argc, argv);
    a = new QtSingleApplication( "TorchManager", argc, argv );
    if ( a->sendMessage( "RUNNING?" ) ) {
        exit(0);
    }


    MainWindow w;
    w.handleMessage("");
    QObject::connect(a, SIGNAL(messageReceived(const QString&)), &w, SLOT(handleMessage(const QString&)));

    QObject::connect(&w, SIGNAL(needToShow()), a, SLOT(activateWindow()));
    a->setActivationWindow(&w, false);
    // Load an application style
    QFile styleFile( ":/Styles/Diablo_III.qss" );
    styleFile.open( QFile::ReadOnly );

    // Apply the loaded stylesheet
    QString style( styleFile.readAll() );
    a->setStyleSheet( style );
    w.setStyle(a->style());
    w.show();
    
    return a->exec();
}
